package com.padakeji.android.tumou.util;

import android.graphics.Bitmap;
import android.widget.ImageView;

import com.nostra13.universalimageloader.cache.memory.impl.UsingFreqLimitedMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
import com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener;
import com.padakeji.android.tumou.TuMouApplication;

/**
 * Created by AtanL on 2015/9/14.
 */
public class ImageLoaderWrapper {

    public static ImageLoaderWrapper instance;

    private ImageLoader imageLoader;

    private ImageLoaderWrapper() {
        imageLoader = ImageLoader.getInstance();
        configureImageLoader();
    }

    private void configureImageLoader() {
        ImageLoaderConfiguration imageLoaderConfiguration = new ImageLoaderConfiguration.Builder(TuMouApplication.getInstance())
                .threadPriority(Thread.NORM_PRIORITY - 2)
                .denyCacheImageMultipleSizesInMemory()
                .memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) // You can pass your own memory cache implementation/你可以通过自己的内存缓存实现
                .memoryCacheSize(2 * 1024 * 1024)
                .writeDebugLogs() // Remove for release app
                .build();//开始构建

        imageLoader.init(imageLoaderConfiguration);
    }

    public synchronized static ImageLoaderWrapper getInstance() {
        if (instance == null) {
            instance = new ImageLoaderWrapper();
        }
        return instance;
    }

    public void display(String uri, ImageView imageView, DisplayImageOptions options, ImageLoadingListener listener, ImageLoadingProgressListener progressListener) {
        imageLoader.displayImage(uri, imageView, options, listener, progressListener);
    }

}
